

import socket, threading
import time
from threading import Thread
import os

f = open("DEAD.txt", "w")
f.write("1")
f.close()



class ClientThread(threading.Thread):
    def __init__(self,clientAddress,clientsocket):
        threading.Thread.__init__(self)
        self.csocket = clientsocket
        print ("Новое подключение: ", clientAddress)

    def run(self):

        msg = ''
        while True:
            data = self.csocket.recv(4096)
            msg = data.decode()
            print(msg)
            self.csocket.send(bytes('Принято!!!','UTF-8'))

            f = open("DEAD.txt", "w")
            f.write("NO")
            f.close()

            if msg == '':
                print("Отключение")
                break


LOCALHOST = "10.8.0.5"
PORT = 7777

server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

server.bind((LOCALHOST, PORT))
print("Сервер запущен!")


def task():
    while True:
        time.sleep(15)
        print("Таймер окончен!")
        
        msgH = open("DEAD.txt", "r")
        msgR = msgH.read()
        qqq = str(msgR)
        print(qqq)

        if qqq == "NO":

            f = open("DEAD.txt", "w")
            f.write("YES")
            f.close()

        else:
            print("GAME OVER!")

            os.system("python3 /home/q/Programms/Dead/1/module.py")

            quit()



def task2():
    while True:
        server.listen(1)
        clientsock, clientAddress = server.accept()
        newthread = ClientThread(clientAddress, clientsock)
        newthread.start()

t1 = Thread(target=task)
t2 = Thread(target=task2)

t1.start()
t2.start()

t1.join()
t2.join()


























